import { scorePoint } from "../../utils/dataMap";
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    practiceId: {
      type: String,
      value: '',
      observer () {
        this.getList()
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    show: false,
    info: app.globalData.userInfo,
    CDNPATH: app.globalData.CDNPATH,
  },

  options: {
    addGlobalClass: true
  },

  created: function () {
    if (this.data.practiceId) {
      this.getList()
      this.setData({
        info: app.globalData.userInfo
      })
    }
    this.getScoreDetailDesc()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getScoreDetailDesc () {
      let mapkey = {
        'scene_integrity': '场景完整度',
        'service_resilience': '服务应变力',
        'scene_proficiency': '场景熟练度',
        'service_performance': '服务表现力',
        'knowledge_accuracy': '知识准确度',
        'speed': '语速',
        'keyword': '缺少关键词',
        'matching_rate': '匹配度',
        'forbidden_word': '违禁词'
      }
      app.api.post({
        url: 'descConfig_getBizDescConfigs',
        data: { descType: 'score_detail_desc' }
      }).then(res => {
        res.map((v, k) => {
          v.content = `${mapkey[v.descSubtype]}：${v.descContent}`
        })
        this.setData({
          contentList: res
        })
        console.log(res)
      })
    },
    close () {
      this.data.show = !this.data.show
      this.setData({
        show: this.data.show
      })
    },
    toggle: function (e) {
      var index = parseInt(e.currentTarget.dataset.bindex)
        this.data.list.map((v, k) => {
          if(index === k) {
            v.open = !v.open
          }
          // v.open = index === k
        })
        this.setData({list: this.data.list})
    },
    chooseScene: function (e) {
      const { index } = e.currentTarget.dataset
      this.setData({
        sceneIndex: index
      })
    },
    getList: function () {
      app.api.post({
        url: 'practice_evaluation_score',
        data: {
          practiceId: this.data.practiceId
        }
      }).then(res => {
        let arr = res.practiceDetailResultList ? res.practiceDetailResultList : []
        console.log(arr)
        arr.map((v, k) => {
          v.open = false
          if (v.evaluationDetailList && v.evaluationDetailList.length > 0) {
            v.evaluationDetailList.map((j, o) => {
              j.ruleName = scorePoint[j.ruleType]
            })
          }
        })
        console.log(res, arr)
        this.setData({
          list: arr
        })
      })
    }
  }
})